<layout name='Layout/layout_main' />
<link type="text/css" href="__PUBLIC__/css/jquery-ui.css" rel="stylesheet"/>
<script type="text/javascript" src="__PUBLIC__/js/jquery-ui.min.js"></script>
<script type="text/javascript">
	function add() {
		window.open("{:U('add')}", "_self");
		return false;
	}

	function edit(){
		id = $("li.tbody.active :checkbox").val();
		if (id == undefined) {
			alert("请选择要编辑的订单");
			return false;
		} else {
			window.open(fix_url("{:U('edit')}?id="+ id), "_self");
		}
	}

	function select_class() {
		winopen("{:U('winpop')}", 600, 400);
	}

	function total_init(){
		$("li.tbody").each(function(){
			total_qty=0;
			$(this).find(".data_item .qty").each(function(){
				total_qty=dec_add(total_qty,$(this).text());
			})
			$(this).find(".data_total .qty").text(total_qty);			
			total_sum=0;
			$(this).find(".data_item .sum").each(function(){
				total_sum=dec_add(total_sum,$(this).text());
			})
			$(this).find(".data_total .sum").text(total_sum);						
		})
		$("li .qty").each(function(){
			$(this).text(formatQty($(this).text()));
		})
		$("li .price,li .sum").each(function(){
			$(this).text(formatMoney($(this).text()));
		})
	}
	function pay(id){
		if(confirm("确定要付款吗？")){
			sendAjax("{:U('pay')}", 'id=' + id,function(data){
				alert(data.info);
		});
		}
	}
	$(document).ready(function() {
		set_return_url();
		total_init();
		$("#start_date").datepicker({
		});
		$("#end_date").datepicker({
		});
		$("#move_to li").click(function(){
			move_to($(this).attr("id"));
		})

		$(".table input:checkbox").click(function(e) {
			$("li.tbody.active").removeClass("active");
			$("li.tbody input:checked").each(function() {
				$(this).parents("li.tbody").addClass("active");
			})
			e.stopPropagation();
		})

		$("li.tbody").click(function() {
			$("li.tbody.active").removeClass("active");
			$(this).addClass("active");
			$(".table input:checkbox").attr("checked", false);
		})
	}); 
</script>
<div class="po">
	<form id="form_search" method='post' >
		<div class="row-fluid title">
			<span>应付款</span>
			<div class="input-append right">
				<input type="text"  onkeydown="key_search();" name="keyword">
				<a class="btn" type="button" onclick="btn_search();"> <i class="icon-search"></i>
				</a>
				<a class="btn" onclick="open_search();"> <i class="icon-angle-down"></i>
				</a>
			</div>
		</div>
		<div class="row-fluid adv_search">
			<div class="row-fluid adv_search_head">
				<h4 class="left">高级搜索</h4>
				<div class="right text-right">
					<a  class="btn" onclick="adv_search();">搜索</a>
					<a  class="btn" onclick="close_search();">关闭</a>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<label class="control-label" for="supplier_name">供应商：</label>
					<div class="controls">
						<div class="input-append">
							<input  type="hidden" id="supplier" name="supplier" class="key" >
							<input  type="text" id="supplier_name" name="supplier_name" class="val"  source="{:U('supplier/json')}" >			
							<button class="btn" type="button"  onclick="select_supplier()" >选择</button>
						</div>
						<div class="search dropdown ">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<label class="control-label" for="start_date">时间：</label>
					<div class="controls">
						<input  type="text" name="start_date" id="start_date" class="input-date" value="{$start_date}"  readonly="readonly">
						&nbsp;~&nbsp;
						<input type="text" name="end_date" id="end_date" value="{$end_date}" readonly="readonly" class="input-date" ></div>
				</div>
			</div>
			<div class="row-fluid form-horizontal">
				<div class="control-group span6">
					<div class="control-group span6">
						<label class="control-label" for="po_no">订单：</label>
						<div class="controls">
								<input  type="text" id="po_no" name="po_no" >
						</div>
					</div>
				</div>
				<div class="control-group span6">
					<div class="control-group span6">
						<label class="control-label" for="gi_no">入库单：</label>
						<div class="controls">
								<input  type="text" id="gi_no" name="gi_no" >
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<form id="form_data" name="form_data" method='post'>
		<input type="hidden" name="ajax" id="ajax" value="1">
		<div class="operate row-fluid">
			<div class="left">
				<a class="btn" onclick="edit();">编辑</a>
				<a class="btn" onclick="mark('del');">删除</a>
			</div>
			<div class="right">
				<a class="btn" onclick="add();">新建</a>
			</div>
		</div>
		<div class="table">
			<ul>
				<li class="thead">
					<div class="row-fluid">
						<div class="span6">
							<span style="width:40%" class="checkbox">
								<div class="wrap">供应商</div>
							</span>
							<span style="width:30%;">单据日期</span>
							<span style="width:30%;">财务日期</span>					
						</div>
						<div class="span6">
							<span style="width:25%;">采购订单</span>
							<span style="width:20%;">预付</span>
							<span style="width:25%;">入库单</span>
							<span style="width:20%;">应付</span>						
							<span style="width:10%;">操作</span>
						</div>
					</div>
						<if condition="count($list) eq 0 ">
							<li class="tbody text-center">
								<h3>没找到相应的数据</h3>
							</li>
						</ul>
				</form>
				<else/>
				<foreach name="list" item="vo">					
						<li class="tbody">
							<div class="row-fluid">
								<div class="span6">
									<span style="width:40%">{$vo.supplier_name}</span>
									<span style="width:30%;"  class="text-center">{$vo.create_time|toDate="Y-m-d"}</span>
									<span style="width:30%;"  class="text-center">{$vo.paid_time|toDate="Y-m-d"}&nbsp;</span>
								</div>
								<div class="span6">
									<span style="width:25%;"  class="text-right">&nbsp;{$vo.po_no}</span>									
									<span style="width:20%;"  class="text-right">&nbsp;{$vo.prepay}</span>
									<span style="width:25%;"  class="text-right">&nbsp;{$vo.gi_no}</span>
									<span style="width:20%;"  class="text-right">&nbsp;{$vo.payable}</span>
									<span style="width:10%;"  class="text-center">
										<neq name="vo.paid" value="1">
											<a onclick="pay({$vo.id})">付款</a>
										</neq>
									</span>
								</div>
							</div>
						</foreach>
					</ul>
				</div>
			</form>
			<div class="page">{$page}</div>
		</if>
	</div>